Previous | Index | Next |

Forward iterators

Forward iterators must implement the methods defined in the interface ForwardIterator api. These requirements are summerized in the table below. Assume that r and s are forward iterators and that v is a value of type Object.

Forward Iterator requirements
expression return type assertion/note
pre/port-condition
r.cmp(s) boolean compare two iterators for equivalence
r.next() Iterator advance the iterator
r.get() Object deference the iterator.
r.put(v) Object deference the iterator for assignment.
r.distance(s) int the number of times r must be advanced, in order to reach s.

NOTE: The fact that r.cmp(s) implies r.next().cmp(s.next()) (which is not true for input and output iterators) and the removal on the restrictions on the number of the assignments through the iterator (which applies to output iterators) allows the use of multi-pass one-directional algorithms with forward iterators.


Previous | Index | Next |